<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    .container {
      width: 800px;
      margin: 10px auto;
    }

    .container h2 {
      text-align: center;
      margin: 30px 0px;
    }
    .row {
      height: 50px;
      display: flex;
      justify-content: center;
      margin-top: 5px;
      line-height: 50px;

    }
    .row span {
      height: 50px;
      width: 100px;
      line-height: 50px;
    }
    .row input {
      height: 50px;
      width: 300px;
      line-height: 50px;
    }
    .row button{
      width: 400px;
      height: 50px;
      color: white;
      background-color: orange;
      border: none;
      border-radius: 10px;
    }
    .row button:active{
      background-color: grey;
    }
  </style>
</head>
<body>
<!-- 这是一个顶层容器，放其他元素 -->
<div class="container">
  <h2>表白墙</h2>
  <div class="row">
    <span>谁</span>
    <input type="text" id="from">
  </div>
  <div class="row">
    <span>对谁</span>
    <input type="text" id="to">
  </div>
  <div class="row">
    <span>说什么</span>
    <input type="text" id="message">
  </div>
  <div class="row">
    <button>提交</button>
  </div>
</div>
<script>
  let container = document.querySelector('.container');
  let fromInput = document.querySelector('#from');
  let toInput = document.querySelector('#to');
  let messageInput = document.querySelector('#message');
  let button = document.querySelector('button');
  button.onclick = function(){
    //1.把用户输入的内容获取到
    let from = fromInput.value;
    let to = toInput.value;
    let message = messageInput.value;
    if(from==''||to==''||message==''){
      return;
    }
    //2.构造一个div,把这个div插入到.container的末尾
    let newDiv = document.createElement('div');
    newDiv.className = 'row';
    newDiv.innerHTML = from + "对" + to +"说:"+message;
    //3.把div挂在container里面
    container.appendChild(newDiv);
  }
</script>
</body>
</html>